Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dexie 3.2.7 → 4.0.4 (major) #3130

Closed
wants to merge 1 commit into from

Conversation

depfu[bot]
Copy link
Contributor

@depfu depfu bot commented Apr 18, 2024

Here is everything you need to know about this upgrade. Please take a good look at what changed and the test results before merging this pull request.

What changed?

✳️ dexie (3.2.7 → 4.0.4) · Repo

Release Notes

4.0.4

Fixes #1955 for real this time (the fix in 4.0.2 wasn't correct enough for npm)

4.0.1

Dexie 4 Stable

After 3 years is alpha and beta, and a week in RC, Dexie@4 is finally out!

Changed Version Handling (PR #1880)

  • Dexie@4 accepts upgrading schema WITHOUT incrementing the version number.
  • Dexie@4 is now able to open a previous version of the database without throwing VersionError.

It's still recommended to increment version number when schema has been updated before publishing new versions of an application since it can make opening the db fractions of ms faster. But it's not required.

(If the native version has diverged from the declared version - which happen when extending schema without incrementing version, dexie need to increment the native version to extend schema - and after a page refresh dexie will detect diverged version by catching VersionError and will redo open with the exact installed version under the hood. When measuring the extra time to open an older version in indexedDB and catch VersionError 10,000 times, it only took 1000 ms - 0.1 ms per try (on a macbook pro), so it should be negligible (https://jsfiddle.net/dfahlander/9tg13fwk/19/))

Cache

Non-transactional live queries utilize memory cache to assist in query resolution. It is possible to opt-out from using the cache using the option {cache: 'disabled'}. The cache can greatly improve simple pure range-based live queries and reduce the queries towards IndexedDB by reusing common queries from different components. The cache will be continously developed and optimized further to improve the new paging support in Dexie 5.0.

Workarounds for flaky browsers

Dexie 4 catches various issues in the IndexedDB support for Chrome and Safari. Without dexie@4 transactions and write operations can suddenly fail in modern versions of Chrome and Safari but dexie makes sure to protect the end user from experience any issues. It does this by reopening the database or redoing the transaction when these things happen - all without the developer having to worry about it. See issues #543 and #613. (A close upcoming release on the 4.0-track will also address #1660 and #1829).

Supports Dexie Cloud

With Dexie 4.0, you can optionally use dexie-cloud-addon and connect your local database with a cloud based database. Dexie Cloud is a complete solution for authorization and synchronization of personal data with support for sharing data between users.

Improved Typing

Dexie 4 has some improved typing. Specifically, Collection.modify() and Table.update() use template literals to suggest code completion and type checking of keypaths to update.

Distinguish insert- from output types

The type passed to db.table.add() can be different from the type returned from db.table.get() and tb.table.toArray(). This mirrors reality better since some properties may be optional when adding (such as an auto-incremented primary key or dexie-cloud properties realmId and owner).

The generic type Table<T, TKey> is extended with a 3rd optional parameter TInsertType making it possible to declare a table as such:

class MyDB extends Dexie {
  friends!: Table<
    { id: number; name: string; age: number }, // T (id is always there)
    number, // TKey (type of primary key)
    { id?: number; name: string; age: number } // TInsertType (id is optional)
  >;
}

A new helper generic EntityTable<T> also exists as a "don't repeat yourself" sugar on top of this, and will also omit any method on the type. In case the type is a mapped class with helper methods, you are still able to pass simple POJO objects
to add() and put() with only data properties.

interface Friend {
  id: number;
  name: string;
  age: number;
}

class MyDB extends Dexie {
friends!: EntityTable<Friend, 'id'>; // Automatically makes id optional when adding and picks its TKey type.
}

If using Dexie Cloud, there's a DexieCloudTable<T> generic that will declare the implicit Dexie Cloud properties on the entity correctly for insert- and output types:

interface Friend {
  id: string;
  name: string;
  age: number;
  realmId: string;
  owner: string;
}

class MyDexieCloudDB extends Dexie {
friends!: DexieCloudTable<Friend, 'id'>; // Makes id, realmId and owner optional on insert operations.
}

A solution to dependency issues with mapped classes

In dexie 3, a mapped class that needs to access the database from its methods, will needs to access the a db instance. But it is a bit awkward to tie a method body to the same instance exported from the db module. For example, having two instances of db with different constructor parameters would not work as both would use one of the instances from their method bodies.

In Dexie 4.0, this is solved using a lightweight dependency injection. There is a generic class Entity that your classes may extend from in order to get your database instance injected as a protected property db on every entity instance. Your class methods can then perform queries onto the db without being dependant on the db module of your app. This use case will require a subclassed Dexie declaration though. There will still be cyclic import dependencies but only on the type level.

export class Friend extends Entity<AppDB> {
  id!: number;
  name!: string;
  age!: number;

async birthday() {
return await this.db.friends.update(this.id, (friend) => ++friend.age);
}
}

Breaking Changes

No IE11 support

No support for Internet Explorer 11, legacy Edge (non-chromium) nor legacy Safari below version 14.

Does any of this look wrong? Please let us know.

Commits

See the full diff on Github. The new version differs by more commits than we can show here.


Depfu Status

Depfu will automatically keep this PR conflict-free, as long as you don't add any commits to this branch yourself. You can also trigger a rebase manually by commenting with @depfu rebase.

All Depfu comment commands
@​depfu rebase
Rebases against your default branch and redoes this update
@​depfu recreate
Recreates this PR, overwriting any edits that you've made to it
@​depfu merge
Merges this PR once your tests are passing and conflicts are resolved
@​depfu cancel merge
Cancels automatic merging of this PR
@​depfu close
Closes this PR and deletes the branch
@​depfu reopen
Restores the branch and reopens this PR (if it's closed)
@​depfu pause
Ignores all future updates for this dependency and closes this PR
@​depfu pause [minor|major]
Ignores all future minor/major updates for this dependency and closes this PR
@​depfu resume
Future versions of this dependency will create PRs again (leaves this PR as is)

@depfu depfu bot added the dependencies Pull requests that update a dependency file label Apr 18, 2024
Copy link

socket-security bot commented Apr 18, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@discoveryjs/[email protected] None 0 81.1 kB lahmatiy
npm/[email protected] None +1 44.2 kB dougwilson
npm/[email protected] None 0 19.7 kB dougwilson
npm/[email protected] None 0 2.94 MB dfahlander
npm/[email protected] None 0 11.4 kB feedic
npm/[email protected] None 0 6.23 kB mafintosh
npm/[email protected] None 0 336 kB ashtuchkin
npm/[email protected] filesystem 0 3.01 kB sindresorhus
npm/[email protected] eval 0 31.9 kB ljharb
npm/[email protected] None 0 10.4 kB isaacs
npm/[email protected] None 0 22.8 kB doowb
npm/[email protected] environment 0 5.81 kB zertosh
npm/[email protected] None 0 206 kB dougwilson
npm/[email protected] None 0 2.97 kB thejameskyle
npm/[email protected] None 0 19.1 kB indutny
npm/[email protected] None 0 10.3 kB dougwilson
npm/[email protected] None 0 8.46 kB dougwilson
npm/[email protected] None 0 42.3 kB chalker
npm/[email protected] None 0 11 kB dougwilson
npm/[email protected] None 0 4.31 kB dougwilson
npm/[email protected] None 0 20.9 kB indutny
npm/[email protected] network +1 122 kB jcoglan

🚮 Removed packages: npm/@babel/[email protected], npm/@babel/[email protected], npm/@types/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected]

View full report↗︎

@depfu depfu bot force-pushed the depfu/update/yarn/dexie-4.0.4 branch from ea854f0 to 3326750 Compare April 29, 2024 08:25
@depfu depfu bot changed the title Update dexie 3.2.6 → 4.0.4 (major) Update dexie 3.2.7 → 4.0.4 (major) Apr 29, 2024
Copy link
Contributor Author

depfu bot commented Jun 1, 2024

Closed in favor of #3166.

@depfu depfu bot closed this Jun 1, 2024
@depfu depfu bot deleted the depfu/update/yarn/dexie-4.0.4 branch June 1, 2024 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants